<template>
    <div class="default-main ba-table-box">
        <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />

        <!-- 表格顶部菜单 -->
        <TableHeader
            :buttons="canOperate&&props.formOperate!=='view'?['refresh', 'add', 'edit', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']:['refresh', 'comSearch', 'quickSearch', 'columnDisplay']"
            :quick-search-placeholder="t('quick Search Placeholder', { fields: t('goods.quick Search Fields') })"
        />

        <!-- 表格 -->
        <!-- 要使用`el-table`组件原有的属性，直接加在Table标签上即可 -->
        <Table ref="tableRef" />

        <!-- 表单 -->
        <PopupForm v-if="baTable.form.operate" />
    </div>
</template>

<script setup lang="ts">
import { ref, provide, onMounted } from 'vue'
import baTableClass from '/@/utils/baTable'
import { goods } from '/@/api/controllerUrls'
import { defaultOptButtons } from '/@/components/table'
import { baTableApi } from '/@/api/common'
import { useI18n } from 'vue-i18n'
import PopupForm from './popupForm.vue'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'
import { useRoute } from 'vue-router'
const { t } = useI18n()

const canOperate = ref(true)

const route = useRoute()
if(route.name == 'goods') canOperate.value = false

const props = defineProps({
    companyName:String,
    formOperate:String
})


const tableRef = ref()
const optButtons = defaultOptButtons(["edit","delete"])
const baTable = new baTableClass(
    new baTableApi(goods),
    {
        pk: 'GOODSID',
        column: [
            { type: 'selection', align: 'center', operator: false },
            // { label: t('goods.GOODSID'), prop: 'GOODSID', align: 'center' },
            { label: t('goods.CORP'), prop: 'CORP', align: 'center' },
            { label: t('goods.GOODS'), prop: 'GOODS', align: 'center' },
            // { label: t('goods.GOODSE'), prop: 'GOODSE', align: 'center' },
            { label: t('goods.ename'), prop: 'ename', align: 'center' },
            { label: t('goods.CIQNO'), prop: 'CIQNO', align: 'center' },
            { label: t('goods.GOODSKIND'), prop: 'GOODSKIND', align: 'center' },
            // { label: t('goods.GOODSPHYLUM'), prop: 'GOODSPHYLUM', align: 'center' },
            // { label: t('goods.TYPE3'), prop: 'TYPE3', align: 'center' },
            { label: t('goods.REMARK'), prop: 'REMARK', align: 'center',show:false ,operator: false},
            { label: t('goods.OP'), prop: 'OP', align: 'center' ,show:false ,operator: false },
            { label: t('goods.OPTIME'), prop: 'OPTIME', align: 'center', render: 'datetime', sortable: 'custom', operator: 'RANGE', width: 160 ,show:false ,operator: false},
            { label: t('goods.unno'), prop: 'unno', align: 'center' ,show:false,operator: false },
            { label: t('goods.pack'), prop: 'pack', align: 'center',show:false ,operator: false },
            { label: t('goods.midu'), prop: 'midu', align: 'center' ,show:false ,operator: false},
            { label: t('goods.flashpoint'), prop: 'flashpoint', align: 'center', operator: 'RANGE',show:false  ,operator: false},
            { label: t('goods.meltingpoint'), prop: 'meltingpoint', align: 'center', operator: 'RANGE',show:false  ,operator: false},
            { label: t('goods.boilingpoint'), prop: 'boilingpoint', align: 'center', operator: 'RANGE' ,show:false ,operator: false},
            { label: t('goods.zhuyi'), prop: 'zhuyi', align: 'center',show:false  ,operator: false},
            { label: t('goods.mpagroup'), prop: 'mpagroup', align: 'center',show:false  ,operator: false},
            { label: t('goods.remind'), prop: 'remind', align: 'center',show:false  ,operator: false},
            { label: t('goods.ems'), prop: 'ems', align: 'center' ,show:false ,operator: false},
            { label: t('goods.mfag'), prop: 'mfag', align: 'center' ,show:false ,operator: false},
            { label: t('goods.page'), prop: 'page', align: 'center' ,show:false ,operator: false},
            { label: t('goods.rmi'), prop: 'rmi', align: 'center',show:false ,operator: false },
            { label: t('goods.ALLOWTYPE'), prop: 'ALLOWTYPES', align: 'center' ,show:false,},
            { label: t('goods.TANKTYPE'), prop: 'TANKTYPE', align: 'center',show:false, operator: false  },
            { label: t('goods.TANKCBM'), prop: 'TANKCBM', align: 'center', show:false,operator: false  },
            { label: t('适装罐型'), prop: 'tank', align: 'center',operator: false },

            { label: t('goods.CASNO'), prop: 'CASNO', align: 'center', show:false,operator: false },
            { label: t('goods.MSDSDATE'), prop: 'MSDSDATE', align: 'center', render: 'datetime', sortable: 'custom', width: 160 ,show:false,operator: false },
            { label: t('goods.STATUS'), prop: 'STATUS', align: 'center', render: 'tag', replaceValue: { 1: t('goods.STATUS 1') } ,show:false,operator: false },
            { label: t('operate'), align: 'center', width: 100, render: 'buttons', buttons: optButtons, operator: false ,show:canOperate.value&&props.formOperate!=='view'},
        ],
        dblClickNotEditColumn: [undefined, ],
        defaultOrder: { prop: 'GOODSID', order: 'desc' },
    },
    {
        defaultItems: [],
    }
)

provide('baTable', baTable)


onMounted(() => {
    baTable.table.ref = tableRef.value
    baTable.mount()
    // baTable.table.filter!.type = '1'
    baTable.table.filter!.CORP = props.companyName

    if(props.formOperate!=='add'){
        baTable.getIndex()?.then(() => {
            baTable.initSort()
            baTable.dragSort()
        })
    }
})
</script>

<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
    name: 'goods',
})
</script>

<style scoped lang="scss"></style>
